<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <#assign base=request.contextPath  />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>密码管理</title>
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css">
    <script type="text/javascript" src="${base}/frame/layui/layui.all.js"></script>
    <link rel="icon" href="${base}/frame/static/image/code.png">
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  		<legend>密码管理</legend>
	</fieldset>
<div style="padding-top: 10px">
    <form class="layui-form" method="get" action="">
        <div class="layui-form-item">
        	<label class="layui-form-label">当前密码</label>
            <div class="layui-input-inline">
                <input type="text" id="password" name="account" class="layui-input" lay-verify="account" placeholder="当前密码" style="width: 300px;"/>
            </div>
        </div>
        <div class="layui-form-item">
        	<label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" id="newpassword1" name="password" class="layui-input" lay-verify="password" placeholder="新密码" style="width: 300px;"/>
            </div>
        </div>    
        <div class="layui-form-item">
        	<label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input type="password" id="newpassword2" name="twopassword" class="layui-input" lay-verify="twopassword" placeholder="确认密码" style="width: 300px;"/>
            </div>
        </div>  
        <div class="layui-form-item">
            <button type="button" class="layui-btn btn-submit layui-btn-danger" lay-submit="" lay-filter="sub"style="width: 300px; margin-left: 110px;"id="update" >保存</button>
        </div>
    </form>
</div>

    <script src="${base}/js/jquery.min.js"></script>
    <script type="text/javascript">
    layui.use(['form', 'layer'], function () {

        // 操作对象
        var form = layui.form
                , layer = layui.layer
                , $ = layui.jquery;

        // 验证
        form.verify({
            account: function (value) {
                if (value == "") {
                    return "请输入当前密码";
                }
            },
            password: function (value) {
                if (value == "") {
                    return "请输入新密码";
                }
            },
            twopassword: function (value) {
                if (value == "") {
                    return "请输入确认密码";
                }
            },
        });

        // // 提交监听
        // form.on('submit(sub)', function (data) {
        //     layer.msg("修改成功")
        // });

     
    })
    //键盘事件
    $("body").bind("keydown",function(e){
        // 兼容FF和IE和Opera
        var theEvent = e || window.event;
        var code=theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code==13) {
            //回车执行查询
            $("#login").click();
        }
    });
    $('#update').on('click',function () {
var password=$("#newpassword1").val();
var password1=$("#newpassword2").val();
if (password==password1 && password!=null && password!=""){
    $.ajax({
    type: "POST",
    url: "${base}/comPtUser/update",
    data: {userName:"${Session["user"].getUserName()}", passWord: $("#password").val(), newpassword1: $("#newpassword1").val()},
    success: function (data) {
        if (data) {
            alert("点击确定将在2秒后跳转登录页面")
            window.setTimeout("window.history.back(-1)",2000);
        } else {alert("修改失败，当前密码不正确")}
    }
});
}if (password!=password1 && password1!=null && password1!="")
  alert("两次密码输入不一致")

    })
</script>
</body>
</html>